package xyz.aikids.spring.modulith.product;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import xyz.aikids.spring.modulith.notification.NotificationDTO;
import xyz.aikids.spring.modulith.notification.internal.Notification;
import xyz.aikids.spring.modulith.notification.NotificationService;
import xyz.aikids.spring.modulith.notification.internal.NotificationType;

import java.util.Date;

/**
 * @author liushouqian
 * @date 2023/7/19 09:31
 * @description
 */
@Slf4j
@Service
public class ProductService {

    private final NotificationService notificationService;

    public ProductService(NotificationService notificationService) {
        this.notificationService = notificationService;
    }

//    public void create(Product product) {
//        notificationService.createNotification(new Notification(new Date(), NotificationType.SMS, product.getName()));
//    }

    public void create(Product product) {
        notificationService.createNotification(new NotificationDTO(new Date(), "SMS", product.getName()));
    }

//    @Autowired
//    private final ApplicationEventPublisher eventPublisher;
//
//    public ProductService(ApplicationEventPublisher events) {
//        this.eventPublisher = events;
//    }
//
//    public void create(Product product) {
//        log.info("***** send notification {} ", product.getName());
//        eventPublisher.publishEvent(new NotificationDTO(new Date(), "SMS", product.getName()));
//    }
}
